<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增单词信息管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wordinfo-add" th:object="${word}">
            <h4 class="form-header h4">单词信息管理信息</h4>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单词外文：</label>
                    <div class="col-sm-8">
                        <input name="name" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">中文翻译：</label>
                    <div class="col-sm-8">
                        <input name="meaning" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">词源：</label>
                    <div class="col-sm-8">
                        <input name="etymology" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">词性：</label>
                    <div class="col-sm-8">
                        <input name="partOfSpeech" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">图片：</label>
                    <div class="col-sm-8">
                        <input type="hidden" id="imageField" name="image" th:value="*{image}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="image" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">语音：</label>
                    <div class="col-sm-8">
                        <input type="hidden" id="soundField" name="sound" th:value="*{sound}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="sound" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">可用状态：</label>
                    <div class="col-sm-8">
                        <select name="status" class="form-control" th:with="type=${@dict.getType('word_status')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单词分组信息</label>
                    <div class="col-sm-8">
                        <div th:with="wordType=${@wordDict.getType()}" class="border p-3 rounded">
                            <div class="form-check" th:each="wordDict : ${wordType}">
                                <input class="form-check-input" type="checkbox" th:id="'group'+${wordDict.id}" th:name="'groupId'" th:value="${wordDict.id}">
                                <label class="form-check-label" th:for="'group'+${wordDict.id}" th:text="${wordDict.value}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "teacher/wordinfo"
        $("#form-wordinfo-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-wordinfo-add').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var hiddenFieldId = this.id + "Field";
            var val = $("#" + hiddenFieldId).val();
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("#" + event.currentTarget.id + "Field").val(data.response.url);
                event.stopPropagation();
                return false;
            }).on('fileremoved', function (event, id, index) {
                $("#" + event.currentTarget.id + "Field").val('')
                event.stopPropagation();
                return false;
            });
            $(this).fileinput('_initFileActions');
        });
    </script>
</body>
</html>